package com.example.mapp.buildSql;

import org.apache.ibatis.jdbc.SQL;

import java.util.List;

public class LowCodeMappingMappSql {

    public String queryList(List<String> codes){

        String select = " * ";
        String table =" low_code_mapping " ;
        String whereParam="";

        if(codes != null && codes.size() > 0){
            StringBuilder str = new StringBuilder();
            for (int i = 0; i < codes.size(); i++) {
                if ("".equals(str.toString())) {
                    str.append("(#{codes["+i+"]}");
                } else {
                    str.append(", #{codes["+i+"]}");
                }
            }
            str.append(")");
            whereParam += " and code in "+str.toString();
        }
        String where = " 1=1 " + whereParam;

        String sql = new SQL(){{
            SELECT(select);
            FROM(table);
            WHERE(where);
            ORDER_BY("ID DESC");
        }
        }.toString();

        return sql;
    }
}
